package com.google.code.greenplate;

import java.util.ArrayList;
import java.util.Arrays;

import android.app.ListActivity;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;

public class RideList extends ListActivity {
	
	private ArrayAdapter<String> mAA;
	private ArrayList<String> mListRides;
	private ListView mListView;
	private String[] mRides;
		
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.ride_list);        
        addWidgets();
        addAdapter();
        setListeners();
    }
    
    public void setListeners() {
    	mListView.setOnItemClickListener(new OnItemClickListener() {
    		public void onItemClick(AdapterView<?> parent, View view, 
    				int position, long id) {
    			// When clicked, show a toast with the TextView text
    			Toast.makeText(getApplicationContext(), ((TextView) view).getText(),
    					Toast.LENGTH_SHORT).show();
                //Intent intent = new Intent();
                //intent.setClass(RideList.this, Contact.class);
                //startActivity(intent);
    		}
    	});
    }

    private void addWidgets() {
    	mListView = getListView();
    }
    
    private void addAdapter() {
    	Resources aResource = this.getResources();
    	mRides = aResource.getStringArray(R.array.rides_array);
    	mListRides = new ArrayList<String>(Arrays.asList(mRides));
    	mAA = new ArrayAdapter<String>(this, R.layout.list_item, mListRides);
    	setListAdapter(mAA);
    }
}